package io.renren.modules.canteens.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.canteens.dao.SupplierDao;
import io.renren.modules.canteens.dto.FoodDTO;
import io.renren.modules.canteens.dto.SupplierDTO;
import io.renren.modules.canteens.entity.FoodEntity;
import io.renren.modules.canteens.entity.SupplierEntity;
import io.renren.modules.canteens.service.SupplierService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 供应商表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Service
public class SupplierServiceImpl extends CrudServiceImpl<SupplierDao, SupplierEntity, SupplierDTO> implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;
    @Override
    public QueryWrapper<SupplierEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<SupplierEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public SupplierDTO getSupplier(String supplierName) {
        SupplierDTO supplier = supplierDao.getSupplier(supplierName);
        return supplier;
    }

    @Override
    public PageData<SupplierDTO> getName(Map<String, Object> params) {
        String supplierName = (String)params.get("supplierName");
        QueryWrapper<SupplierEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(supplierName), "supplier_name", supplierName);
        IPage<SupplierEntity> page = baseDao.selectPage(
                getPage(params, null, false),
                wrapper);
        PageData<SupplierDTO> pageData = getPageData(page, SupplierDTO.class);
        return pageData;
    }

    @Override
    public List<SupplierDTO> getLikeName(String supplierName) {
        List<SupplierDTO> likeName = supplierDao.getLikeName(supplierName);
        return likeName;
    }
}